package cn.buk.tms.eotms.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;

import jakarta.persistence.*;
import java.util.Date;

/**
 * @author yfdai
 * @description 操作日志
 */
@Entity
@Table(name="operation_log")
public class OperationLog {


    public static OperationLog createLog(int enterpriseId, int objectType) {
        OperationLog log = new OperationLog();
        log.setEnterpriseId(enterpriseId);
        log.setObjectType(objectType);

        return log;
    }


    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private int id;

    @Column(name = "enterprise_id")
    private int enterpriseId;

    /**
     * 所对应的客户ID，允许客户自己查看的日志
     */
    @Column(name = "customer_id")
    private Integer customerId;

    /**
     * 操作对象的类型
     * 0 - 机票订单
     * 1 - 退票单
     * 2 - 服务单
     * 10 - 账单
     */
    @Column(name = "object_type")
    private int objectType;

    @Column(name="order_id")
    private int orderId;

    /**
     * 操作员的用户名
     */
    @Column(length = 32)
    private String operator;

    /**
     * 操作记录内容
     */
    private String content;

    /**
     * 操作时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" ,timezone="GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "create_time", insertable = false)
    private Date createTime;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        if (content != null && content.length() > 200) {
            content = content.trim().substring(0, 200);
        }
        this.content = content;
    }

    public int getOrderId() {
        return orderId;
    }

    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public int getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(int enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public int getObjectType() {
        return objectType;
    }

    public void setObjectType(int objectType) {
        this.objectType = objectType;
    }

    public Integer getCustomerId() {
        return customerId;
    }

    public void setCustomerId(Integer customerId) {
        this.customerId = customerId;
    }
}
